package handler.pub;


import bean.command.RbCmd;
import bean.orderbook.MatchEvent;
import handler.BaseHandler;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap;
import org.eclipse.collections.impl.map.mutable.primitive.ShortObjectHashMap;
import thirdpart.hq.L1MarketData;
import thirdpart.hq.MatchData;
import thirdpart.order.CmdType;

import java.util.List;


@Log4j2
@RequiredArgsConstructor
public class L1PubHandler extends BaseHandler {

    @NonNull
    private final ShortObjectHashMap<List<MatchData>> matcherEventMap;

    @Override
    public void onEvent(RbCmd cmd, long l, boolean b) throws Exception {
        final CmdType cmdType = cmd.command;
        if(cmdType==CmdType.NEW_ORDER||cmdType==CmdType.CANCEL_ORDER){
            for(MatchEvent e:cmd.matchEventList){
                matcherEventMap.get((short) e.mid).add(e.copy());
//                log.info("当前委托{}",cmd);
            }
        }else if(cmdType==CmdType.HQ_PUB){
            // 1. 五档行情
            pubMarketData(cmd.marketDataMap);
            // 2. 客户成交的行情
            pubMatcherData();

        }
    }

    private void pubMatcherData() {
        log.info("发布交易数据");
    }

    private void pubMarketData(IntObjectHashMap<L1MarketData> marketDataMap) {
        log.info(marketDataMap);
        log.info("发布行情数据");
    }

}
